package com.example.treeHole.controller;

import com.example.treeHole.result.Result;
import com.example.treeHole.service.NotificationMainService;
import com.example.treeHole.vo.NotificationMain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/notification")
public class NotificationMainController {

    @Autowired
    public NotificationMainService notificationMainService;

    /**
     * 根据条件查询通知
     * @param type
     * @return
     */
    @GetMapping("/findByType/{type}")
    public Result<List<NotificationMain>> findByType(@PathVariable String type ){
        if ("".equals(type)){
            return Result.error("参数异常");
        }
        //系统消息
        List<NotificationMain> notificationMainList=new ArrayList<>();
        if("1".equals(type)){
            List<NotificationMain> notificationMainList1=notificationMainService.findSysByType(type);
            notificationMainList.addAll(notificationMainList1);
        }else if("2".equals(type)){
            //回复评论的
            List<NotificationMain> notificationMainList2=notificationMainService.findByType(type);
            notificationMainList.addAll(notificationMainList2);
        }else {
            //回复回复的
            List<NotificationMain> notificationMainList3=notificationMainService.findByType(type);
            notificationMainList.addAll(notificationMainList3);
        }
        return Result.success(notificationMainList);
    }

    @PostMapping("/approve/{articleId}")
    public Result approve(@PathVariable String articleId){
        notificationMainService.approve(articleId);
        return Result.success();
    }

    @PostMapping("/approve1/{articleId}")
    public Result approve1(@PathVariable String articleId){
        notificationMainService.approve1(articleId);
        return Result.success();
    }


}
